<?php

class Zend_View_Helper_CartProductColors extends Zend_View_Helper_Abstract
{

	/**
	 * @param Sherpa_Model_Icon $icon
	 * @return string
	 */
	public function cartProductColors(Sherpa_Model_Colors $colors)
	{
		$xhtml = $this->_getColorImage($colors);
		$xhtml .= sprintf('<span style="padding-left:5px">%s</span>', $colors->getColorNames());
		return $xhtml;
	}

	/**
	 * @param Sherpa_Model_Colors $colors
	 * @return string
	 */
	private function _getColorImage(Sherpa_Model_Colors $colors)
	{
		$xhtml = '<span>';
		$count = $colors->count();
		$imgTag = '<img src="sherpa/img/clear.gif" width="%d" height="11" style="vertical-align:baseline;background-color:#%s;" alt="" />';
		if($count == 1) {
			$xhtml .= sprintf($imgTag, 11, $colors->current()->getRgbHex());
		} elseif ($count == 2) {
			foreach($colors AS $color) {
				$xhtml .= sprintf($imgTag, 5, $color->getRgbHex());
			}
		}
		$xhtml .= '</span>';
		return $xhtml;
	}

}